
var portal = {
		editInfo : function(value){
			var URL = baseURL + "/system/user/editInfo";
			var param = {};
			var title = 
			param.userName = value;
			common.dialog({
				obj : "#editUserInfoForm",
				url : URL,
				param : param,
				title : title,
				width : 400,
				confirm : function() {
					if($("#editUserInfoForm").form('validate')==true){
						// Click the "Confirm" button to save user info.
						portal.saveinfo();
					}
					else{
						common.showTip({
							title : localeMsg.common.warn,
							text : localeMsg.common.invalidData
						});
					}
				}
			});
		},
		
		editPassword : function(value){
			var URL = baseURL + "/system/user/editPassword";
			var param = {};
			var title = 
			param.userName = value;
			common.dialog({
				obj : "#editUserPasswordForm",
				url : URL,
				param : param,
				title : title,
				width : 400,
				confirm : function() {
					if($("#editUservForm").form('validate')==true){
						// Click the "Confirm" button to save user info.
						portal.savepassword();
					}
					else{
						common.showTip({
							title : localeMsg.common.warn,
							text : localeMsg.common.invalidData
						});
					}
				}
			});
		},
		
		saveinfo : function(){
				$("#editUserinfoForm").ajaxSubmit({
					success : function(json) {
						// Save successfully and refresh the user list.
						if (json.result && json.result == "success") {
							common.showTip({
								success : true,
								title : localeMsg.common.info,
								text : localeMsg.common.saveSuccess,
							});
						} else {
							common.showTip({
								title : localeMsg.common.warn,
								text : localeMsg.common.saveFailed,
								success : false
							});
						}
					}
				});

		},
		
		savepassword : function(){
			if( $("#NewPassword").eq(0).val()==$("#confirmNewPassword").eq(0).val()){
			var param = {};
			param.oldW = $("#originalPassword").eq(0).val();
			param.newW = $("#NewPassword").eq(0).val();
			param.userId = $("#userId").eq(0).val();
				$.ajax({
					type : "post",
					url : baseURL + "/system/user/savepassword",
					data : param,
					traditional: true,
					dataType : "json",
					success : function(json) {
						if (json.result && json.result == "success") {
							common.showTip({
								success : true,
								title : localeMsg.common.info,
								text : localeMsg.common.saveSuccess,
							});
						} else {
							if (json.result && json.result == "wrong"){
								common.showTip({
									success : false,
									title : localeMsg.common.warn,
									text : localeMsg.user.wrong_password,
								});
							}else{
								common.showTip({
									success : false,
									title : localeMsg.common.warn,
									text : localeMsg.common.saveFailed,
								});
							}
						}
					}
					
				});
			}
			else{
				common.showTip({
					title : localeMsg.common.warn,
					text : localeMsg.user.password,
				});
			}
		},
		
		alarmCouunt : function(){
			
			$.ajax({
				type : "get",
				url : baseURL + "/system/alarm/count",
				data : param,
				traditional: true,
				dataType : "json"
/*				success : function(json) {
					if (json.result && json.result == "success") {
						common.showTip({
							success : true,
							title : localeMsg.common.info,
							text : localeMsg.common.saveSuccess,
						});
					} else {
						if (json.result && json.result == "wrong"){
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.user.wrong_password,
							});
						}else{
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.common.saveFailed,
							});
						}
					}
				}*/
			});
		},
		
		validateInfo : function(){
			
		    $('#editFullName').validatebox({
		        required: true,
		        validType: ['minLength[1]','maxLength[20]','name']
		    });
		    $('#editMobliePhone').validatebox({
		        required: true,
		        validType: ['minLength[11]','maxLength[11]','digits']
		    });
		    
		    $('#editEMail').validatebox({
		        required: true,
		        validType: 'email'
		    });
		},
		
		validatePassword :function(){
		    $('#originalPassword').validatebox({
		        required: true,
		        validType: ['minLength[6]','maxLength[50]']
		    });
		    $('#NewPassword').validatebox({
		        required: true,
		        validType: ['minLength[6]','maxLength[50]']
		    });
		    $('#confirmNewPassword').validatebox({
		        required: true,
		        validType: ['minLength[6]','maxLength[50]']
		    });
		},
		
		forwardToAlarm : function(message){
			$("#alarmInput").val(message);
			$("#alarmForm").submit();
		}
};